﻿using System;
using System.Data.SqlClient;
using Devv.Core.UniDataTier;
using Yglu.BusinessLayer.Entities;

namespace Yglu.BusinessLayer
{
	public partial class DataAccess
	{
		#region Get

		public static SqlDataReader AdminLog_Get(User user)
		{
			DataHandler db = new DataHandler();

			db.AddParameter("@UserId", user.Id);

			return (SqlDataReader)db.ExecuteReader("upAdminLog_Get");
		}

		#endregion

		#region Insert and update

		public static void AdminLog_Insert(AdminLog log)
		{
			using (DataHandler db = new DataHandler())
			{
				if (log.User != null && log.User.Id > 0)
				{
					db.AddParameter("@UserId", log.User.Id);
				}
				
				db.AddParameter("@Message", log.Message);
				db.AddParameter("@Page", log.Page);
				db.AddParameter("@DateRecorded", DateTime.Now);
				db.AddParameter("@Active", true);

				log.Id = Convert.ToInt32(db.ExecuteScalar("upAdminLog_Insert"));
			}
		}

		#endregion
	}
}